/*
 * General.java
 *
 * Created on 16 de julio de 2006, 0:31
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package futbol;

import java.awt.Toolkit;
import resource.LoadResource;

/**
 *
 * @author Administrador
 */
public class General {
    
    public static double getAngulo(double x0, double y0, double xD, double yD){
        double ang=0;
        double dy=yD-y0;
        double dx=xD-x0;
        if (dx>0) ang=Math.atan(dy/dx);
        else if (dx<0) ang=Math.atan(dy/dx)+Math.PI;
        else if (y0<yD) ang=Math.PI/2;
        else ang=-Math.PI/2;
        ang=corregirAngulo(ang);
        return ang;
    }
    
    public static double corregirAngulo(double ang){
        while (ang<0)
            ang+=Math.PI*2;
        while (ang>=Math.PI*2)
            ang-=Math.PI*2;
        return ang;
    }
    
    public static double getDistancia(double x1, double y1, double x2, double y2){
        return Math.sqrt(Math.pow(x1-x2,2)+Math.pow(y1-y2,2));
    }
    
    public static String format(int min, int seg){
        String sMin=""+min, sSeg=""+seg;
        if (min<10) sMin="0"+min;
        if (seg<10) sSeg="0"+seg;
        return sMin + ":" + sSeg;
    }
    
    public static int control(int numero, int min, int max){
        if (numero<min) return min;
        if (numero>max) return max;
        return numero;
    }
    
    public static void indicarGol()
    {
        LoadResource.getDefault().playSoundSilbato();
    }

    public static void indicarSaqueDeCentro()
    {
        LoadResource.getDefault().playSoundSilbato();
    }
    
    public static void esperarSaqueDeCentro()
    {
      try
      {
        Thread.sleep(2000) ;
      }
      catch (InterruptedException ex)
      {
        ex.printStackTrace();
      }
      
      indicarSaqueDeCentro() ;
    }
    
    
}
